package com.shangdiao.sd_server.p_client.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shangdiao.sd_server.constant.Constant;
import com.shangdiao.sd_server.constant.ErrorCode;
import com.shangdiao.sd_server.generator.pojo.SdCertificate;
import com.shangdiao.sd_server.generator.pojo.SdCertificateExample;
import com.shangdiao.sd_server.generator.pojo.SdDicLabel;
import com.shangdiao.sd_server.generator.pojo.SdDicLabelExample;
import com.shangdiao.sd_server.generator.pojo.SdEduExp;
import com.shangdiao.sd_server.generator.pojo.SdFeedback;
import com.shangdiao.sd_server.generator.pojo.SdInExp;
import com.shangdiao.sd_server.generator.pojo.SdLabel;
import com.shangdiao.sd_server.generator.pojo.SdLabelExample;
import com.shangdiao.sd_server.generator.pojo.SdOutExp;
import com.shangdiao.sd_server.generator.pojo.SdPerson;
import com.shangdiao.sd_server.generator.pojo.SdPersonBase;
import com.shangdiao.sd_server.generator.pojo.SdPersonPhoto;
import com.shangdiao.sd_server.generator.pojo.SdPersonPhotoExample;
import com.shangdiao.sd_server.pojo.ResponseMsg;
import com.shangdiao.sd_server.pojo.Row;
import com.shangdiao.sd_server.service.DicService;
import com.shangdiao.sd_server.service.PersonService;
import com.shangdiao.sd_server.service.SequenceService;
import com.shangdiao.sd_server.util.CommonUtil;
import com.shangdiao.sd_server.util.DateUtil;
import com.shangdiao.sd_server.util.MD5Util;
import com.shangdiao.sd_server.util.RequestUtil;
import com.shangdiao.sd_server.util.StringUtil;

/**
 * 个人管理信息
 * @author mary
 *
 */
@Controller
@RequestMapping("/person/info")
public class EmployInfoController {
	
	@Autowired
	PersonService personService;
	@Autowired
	DicService dicService;
	@Autowired
	SequenceService sequenceService;
	
	
	@RequestMapping(value = { "/updateBaseInfo.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg updateBaseInfo(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			String personName = RequestUtil.get(request, "personName");
			Integer personGender = RequestUtil.getInt(request, "personGender");
			String birthday = RequestUtil.get(request, "birthday");
			String tel = RequestUtil.get(request, "tel");
			String email = RequestUtil.get(request, "email");
			Integer districtId = RequestUtil.getInt(request, "districtId");
			String district = RequestUtil.get(request, "district");
			Integer postFlag = RequestUtil.getInt(request, "postFlag", Constant.POST_FLAG_PARTTIME);//1实习2兼职,默认2
			Integer dicFieldId = RequestUtil.getInt(request, "dicFieldId");
			String dicFieldName = RequestUtil.get(request, "dicFieldName");
			Integer universityId = RequestUtil.getInt(request, "universityId");
			String university = RequestUtil.get(request, "university");
			String college = RequestUtil.get(request, "college");
			String major = RequestUtil.get(request, "major");
			String admissionDate = RequestUtil.get(request, "admissionDate");
			Integer dicEducationId = RequestUtil.getInt(request, "dicEducationId");
			String dicEducationName = RequestUtil.get(request, "dicEducationName");
			String logo = RequestUtil.get(request, "logo");
			String card = RequestUtil.get(request, "card");
			if(personId == 0){
				retMsg = new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
				return retMsg;
			}
			if(!StringUtil.isBlank(email) && !StringUtil.isEmail(email)){
				retMsg = new ResponseMsg("邮箱格式错误", ErrorCode.ERROR, null);
				return retMsg;
			}
			if(!StringUtil.isBlank(tel) && !StringUtil.isMobile(tel)){
				retMsg = new ResponseMsg("手机号格式错误", ErrorCode.ERROR, null);
				return retMsg;
			}
			boolean cardFlag = true;
			boolean logoFlag = true;
			if(!StringUtil.isBlank(card)){
				card = card.substring(card.lastIndexOf("/") + 1, card.length());
				cardFlag = CommonUtil.Move(Constant.TEMP_FILE_PATH + card, Constant.LOGO_FILE_PATH + card);
			}
			if(!StringUtil.isBlank(logo)){
				logo = logo.substring(logo.lastIndexOf("/") + 1, logo.length());
				logoFlag = CommonUtil.Move(Constant.TEMP_FILE_PATH + logo, Constant.LOGO_FILE_PATH + logo);
			}
			if(cardFlag && logoFlag){
				SdPerson person = personService.selectPersonById(personId);
				SdPersonBase personBase = personService.selectPersonBaseById(personId);
				personBase.setPersonId(personId);
				personBase.setEmail(email);
				personBase.setPersonName(personName);
				if(!StringUtil.isBlank(logo)){
					personBase.setLogo(Constant.LOGO_FILE_URL + logo);
				}
				personBase.setUniversityId(universityId);
				personBase.setUniversity(university);
				personService.updatePersonBaseById(personBase);
				person.setPersonId(personId);
				person.setPersonName(personName);
				person.setPersonGender(personGender);
				person.setBirthday(DateUtil.StringtoDate(birthday, DateUtil.LONG_DATE_FORMAT));
				person.setTel(tel);
				person.setEmail(email);
				person.setDistrictId(districtId);
				person.setDistrict(district);
				person.setPostFlag(postFlag);
				person.setDicFieldId(dicFieldId);
				person.setDicFieldName(dicFieldName);
				person.setUniversityId(universityId);
				person.setUniversity(university);
				person.setCollege(college);
				person.setMajor(major);
				person.setAdmissionDate(DateUtil.StringtoDate(admissionDate, DateUtil.FORMAT_MONTH));
				person.setDicEducationId(dicEducationId);
				person.setDicEducationName(dicEducationName);
				if(!StringUtil.isBlank(card)){
					person.setCard(Constant.LOGO_FILE_URL + card);
				}
				personService.updatePersonById(person);
				return new ResponseMsg("更新成功", ErrorCode.OK, null);
			}else{
				return new ResponseMsg("移动文件失败", ErrorCode.ERROR, null);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("更新失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 教育经历
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/insertEduExp.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg insertEduExp(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			Integer expId = RequestUtil.getInt(request, "expId");
			Integer universityId = RequestUtil.getInt(request, "universityId");
			String university = RequestUtil.get(request, "university");
			String major = RequestUtil.get(request, "major");
			String startDate = RequestUtil.get(request, "startDate");
			String endDate = RequestUtil.get(request, "endDate");
			Integer del = RequestUtil.getInt(request, "del");
			if(personId == 0){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdEduExp eduExp = new SdEduExp();
			eduExp.setPersonId(personId);
			eduExp.setUniversityId(universityId);
			eduExp.setUniversity(university);
			eduExp.setMajor(major);
			eduExp.setStartDate(DateUtil.StringtoDate(startDate, DateUtil.FORMAT_MONTH));
			eduExp.setEndDate(DateUtil.StringtoDate(endDate, DateUtil.FORMAT_MONTH));
			if(expId == null){//新增
				eduExp.setCreateTime(new Date());
				personService.insertEduExp(eduExp);
				return new ResponseMsg("新增成功", ErrorCode.OK, null);
			}else{//更新
				eduExp.setExpId(expId);
				eduExp.setDel(del);
				personService.updateEduExp(eduExp);
				return new ResponseMsg("更新成功", ErrorCode.OK, null);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	/**
	 * 校内经历
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/insertInExp.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg insertInExp(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			Integer expId = RequestUtil.getInt(request, "expId");
			String expName = RequestUtil.get(request, "expName");
			String startDate = RequestUtil.get(request, "startDate");
			String endDate = RequestUtil.get(request, "endDate");
			String description = RequestUtil.get(request, "description");
			Integer del = RequestUtil.getInt(request, "del");
			if(personId == null){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdInExp inExp = new SdInExp();
			inExp.setPersonId(personId);
			inExp.setExpName(expName);
			inExp.setStartDate(DateUtil.StringtoDate(startDate, DateUtil.FORMAT_MONTH));
			inExp.setEndDate(DateUtil.StringtoDate(endDate, DateUtil.FORMAT_MONTH));
			inExp.setDescription(description);
			if(expId == null){//新增
				inExp.setCreateTime(new Date());
				personService.insertInExp(inExp);
				return new ResponseMsg("新增成功", ErrorCode.OK, null);
			}else{//更新
				inExp.setExpId(expId);
				inExp.setDel(del);
				personService.updateInExp(inExp);
				return new ResponseMsg("更新成功", ErrorCode.OK, null);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 校外实践
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/insertOutExp.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg insertOutExp(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			Integer expId = RequestUtil.getInt(request, "expId");
			String expName = RequestUtil.get(request, "expName");
			String startDate = RequestUtil.get(request, "startDate");
			String endDate = RequestUtil.get(request, "endDate");
			String description = RequestUtil.get(request, "description");
			Integer del = RequestUtil.getInt(request, "del");
			if(personId == null){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdOutExp outExp = new SdOutExp();
			outExp.setPersonId(personId);
			outExp.setExpName(expName);
			outExp.setStartDate(DateUtil.StringtoDate(startDate, DateUtil.FORMAT_MONTH));
			outExp.setEndDate(DateUtil.StringtoDate(endDate, DateUtil.FORMAT_MONTH));
			outExp.setDescription(description);
			if(expId == null){//新增
				outExp.setCreateTime(new Date());
				personService.insertOutExp(outExp);
				return new ResponseMsg("新增成功", ErrorCode.OK, null);
			}else{//更新
				outExp.setExpId(expId);
				outExp.setDel(del);
				personService.updateOutExp(outExp);
				return new ResponseMsg("更新成功", ErrorCode.OK, null);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("服务器出错", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	
	/**
	 * 新增个人标签
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/insertLabel.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg insertLabel(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			String dicLabelIdList = RequestUtil.get(request, "dicLabelIdList");
			String dicLabelNameList = RequestUtil.get(request, "dicLabelNameList");
			if(personId == null){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			//删掉个人现有标签
			SdLabelExample labelExample = new SdLabelExample();
			labelExample.or().andPersonIdEqualTo(personId)
				.andDelEqualTo(Constant.DEL_NO);
			SdLabel label = new SdLabel();
			label.setDel(Constant.DEL_YES);
			personService.updateLabel(label, labelExample);
			
			String[] labelIdArr = dicLabelIdList.split(",");
			String[] labelNameArr = dicLabelNameList.split(",");
			for(int i = 0; i < labelIdArr.length; i ++){
				String labelIdStr = labelIdArr[i];
				String labelName = labelNameArr[i];
				Integer dicLabelId = Integer.parseInt(labelIdStr);
				if(dicLabelId == 0){
					dicLabelId = sequenceService.nextSequence("SD_DIC_LABEL");
					SdDicLabel dicLabel = new SdDicLabel();
					dicLabel.setDicLabelId(dicLabelId);
					dicLabel.setDicLabelName(labelName);
					dicLabel.setPersonId(personId);
					dicLabel.setDel(Constant.DEL_NO);
					dicService.insertDicLabel(dicLabel);
				}
				label = new SdLabel();
				label.setPersonId(personId);
				label.setDicLabelId(dicLabelId);
				label.setDicLabelName(labelName);
				label.setCreateTime(new Date());
				personService.insertLabel(label);
			}
			return new ResponseMsg("新增成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("新增失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 删除个人标签字典
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/deleteDicLabel.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg deleteLabel(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer dicLabelId = RequestUtil.getInt(request, "dicLabelId");
			if(dicLabelId == null){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdDicLabel dicLabel = new SdDicLabel();
			dicLabel.setDicLabelId(dicLabelId);
			dicLabel.setDel(Constant.DEL_YES);
			dicService.updateDicLabel(dicLabel);
			return new ResponseMsg("删除成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("删除失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 自我评价
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/updateSelfEvaluation.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg updateSelfEvaluation(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			String selfEvaluation = RequestUtil.get(request, "selfEvaluation");
			if(personId == null){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdPerson person = new SdPerson();
			person.setPersonId(personId);
			person.setSelfEvaluation(selfEvaluation);
			personService.updatePersonById(person);
			return new ResponseMsg("更新成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("更新失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 新增证书和个人风采照片
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/insertPhoto.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg insertPhoto(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			String certUrlListNew = RequestUtil.get(request, "certUrlList");//证书图片
			String photoUrlListNew = RequestUtil.get(request, "photoUrlList");//个人风采图片
			if(personId == 0 ){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			//证书图片
			if(!StringUtil.isBlank(certUrlListNew)){
				//先将之前保存的删除
				SdCertificateExample certExample = new SdCertificateExample();
				certExample.or().andPersonIdEqualTo(personId)
					.andDelEqualTo(Constant.DEL_NO);
				List<SdCertificate> certList = personService.selectCertificateByExample(certExample); 
				List<String> certUrlList = new ArrayList<String>();
				for(SdCertificate cert : certList){
					String certUrl = cert.getCertUrl(); 
					certUrl = certUrl.substring(certUrl.lastIndexOf("/") + 1, certUrl.length());
					certUrlList.add(Constant.PHOTO_FILE_PATH + certUrl);
					cert.setDel(Constant.DEL_YES);
					personService.updateCertificate(cert);
				}
				//删除文件
				CommonUtil.deleteMoreFile(certUrlList);
				//新增
				String[] certUrlArr = certUrlListNew.split(",");
				for(String certUrl : certUrlArr){
					certUrl = certUrl.substring(certUrl.lastIndexOf("/") + 1, certUrl.length());
					boolean logoFlag = CommonUtil.Move(Constant.TEMP_FILE_PATH + certUrl, Constant.PHOTO_FILE_PATH + certUrl);
					if(logoFlag){
						SdCertificate certificate = new SdCertificate();
						certificate.setPersonId(personId);
						certificate.setCertUrl(Constant.PHOTO_FILE_URL + certUrl);
						certificate.setCreateTime(new Date());
						personService.insertCertificate(certificate);
					}
				}
			}
			//个人风采照片
			if(!StringUtil.isBlank(photoUrlListNew)){
				//先将之前保存的删除
				SdPersonPhotoExample photoExample = new SdPersonPhotoExample();
				photoExample.or().andPersonIdEqualTo(personId)
					.andDelEqualTo(Constant.DEL_NO);
				List<SdPersonPhoto> photoList = personService.selectPersonPhotoByExample(photoExample); 
				List<String> photoUrlList = new ArrayList<String>();
				for(SdPersonPhoto photo : photoList){
					String photoUrl = photo.getPersonPhotoUrl(); 
					photoUrl = photoUrl.substring(photoUrl.lastIndexOf("/") + 1, photoUrl.length());
					photoUrlList.add(Constant.PHOTO_FILE_PATH + photoUrl);
					photo.setDel(Constant.DEL_YES);
					personService.updatePhoto(photo);
				}
				//删除文件
				CommonUtil.deleteMoreFile(photoUrlList);
				//新增
				String[] photoUrlArr = photoUrlListNew.split(",");
				for(String photoUrl : photoUrlArr){
					photoUrl = photoUrl.substring(photoUrl.lastIndexOf("/") + 1, photoUrl.length());
					boolean logoFlag = CommonUtil.Move(Constant.TEMP_FILE_PATH + photoUrl, Constant.PHOTO_FILE_PATH + photoUrl);
					if(logoFlag){
						SdPersonPhoto personPhoto = new SdPersonPhoto();
						personPhoto.setPersonId(personId);
						personPhoto.setPersonPhotoUrl(Constant.PHOTO_FILE_URL + photoUrl);
						personPhoto.setCreateTime(new Date());
						personService.insertPhoto(personPhoto);
					}
				}
			}
			return new ResponseMsg("新增成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("新增失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	

	/**
	 * 删除证书技能
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/deleteCertificate.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg deleteCertificate(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer certId = RequestUtil.getInt(request, "certId");
			if(certId == null){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdCertificate certificate = personService.selectCertificateById(certId);
			String certUrl = certificate.getCertUrl();
			certificate.setDel(Constant.DEL_YES);
			personService.updateCertificate(certificate);
			certUrl = certUrl.substring(certUrl.lastIndexOf("/") + 1, certUrl.length());
			CommonUtil.deleteFile(Constant.PHOTO_FILE_PATH + certUrl);
			return new ResponseMsg("删除成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("删除失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 删除个人风采照片
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/deletePhoto.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg deletePhoto(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personPhotoId = RequestUtil.getInt(request, "personPhotoId");
			if(personPhotoId == null){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			
			SdPersonPhoto personPhoto = personService.selectPersonPhotoById(personPhotoId);
			String photoUrl = personPhoto.getPersonPhotoUrl();
			personPhoto.setDel(Constant.DEL_YES);
			personService.updatePhoto(personPhoto);
			photoUrl = photoUrl.substring(photoUrl.lastIndexOf("/") + 1, photoUrl.length());
			CommonUtil.deleteFile(Constant.PHOTO_FILE_PATH + photoUrl);
			return new ResponseMsg("删除成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("删除失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 查询可选标签
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/selectLabel.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg selectLabel(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			//字典表标签
			List<String> category_list = dicService.selectLabelCategory();
			List<Row> resultList = new ArrayList<Row>();
			for(String category : category_list){
				Row result = new Row();
				SdDicLabelExample example = new SdDicLabelExample();
				example.or().andCategoryEqualTo(category).andPersonIdIsNull().andDelEqualTo(Constant.DEL_NO);
				List<SdDicLabel> label_list = dicService.selectByExample(example);
				result.put("categoryName", category);
				result.put("categoryDetail", label_list);
				resultList.add(result);
			}
			//自定义标签
			Row result = new Row();
			SdDicLabelExample example = new SdDicLabelExample();
			example.or().andPersonIdEqualTo(personId).andDelEqualTo(Constant.DEL_NO);
			List<SdDicLabel> label_list = dicService.selectByExample(example);
			result.put("categoryName", "我的标签");
			result.put("categoryDetail", label_list);
			resultList.add(result);
			return new ResponseMsg("查询成功", ErrorCode.OK, resultList);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("删除失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	/**
	 * 删除我的自定义标签
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "/deleteMyDicLabel.json" })
	@ResponseBody
	@Transactional
	public ResponseMsg deleteMyDicLabel(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer dicLabelId = RequestUtil.getInt(request, "dicLabelId");
			if(dicLabelId == null){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdDicLabel dicLabel = new SdDicLabel();
			dicLabel.setDicLabelId(dicLabelId);
			dicLabel.setDel(Constant.DEL_YES);
			dicService.updateDicLabel(dicLabel);
			return new ResponseMsg("删除成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("删除失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	
	@RequestMapping(value = { "/resetPwd.json" })
	@ResponseBody
	public ResponseMsg resetPwde(HttpServletRequest request, HttpServletResponse response) {
		try{
			String oldPwd = RequestUtil.get(request, "oldPwd");
			String newPwd = RequestUtil.get(request, "newPwd");
			Integer personId = RequestUtil.getInt(request, "uid");
			if(StringUtil.isBlank(oldPwd) || StringUtil.isBlank(newPwd)){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdPersonBase personBase = personService.selectPersonBaseById(personId);
			if(personBase.getPwd().equals(MD5Util.encodeByMD5(oldPwd))){
				personBase.setPwd(MD5Util.encodeByMD5(newPwd));
				personService.updatePersonBaseById(personBase);
				return new ResponseMsg("修改密码成功", ErrorCode.OK, null);
			}else{
				return new ResponseMsg("原密码错误", ErrorCode.ERROR, null);
			}
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("修改密码失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/setIsInvited.json" })
	@ResponseBody
	public ResponseMsg setIsInvited(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			Integer isInvited = RequestUtil.getInt(request, "isInvited");
			if(personId == 0 ){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdPerson person = new SdPerson();
			person.setPersonId(personId);
			person.setIsInvited(isInvited);
			personService.updatePersonById(person);
			return new ResponseMsg("操作成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("修改密码失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	@RequestMapping(value = { "/feedback.json" })
	@ResponseBody
	public ResponseMsg feedback(HttpServletRequest request, HttpServletResponse response) {
		try{
			Integer personId = RequestUtil.getInt(request, "uid");
			String content = RequestUtil.get(request, "content");
			if(personId == 0 ){
				return new ResponseMsg("缺少必要参数", ErrorCode.ERROR, null);
			}
			SdFeedback feedback = new SdFeedback();
			feedback.setContent(content);
			feedback.setUserId(personId);
			feedback.setEntryFlag("p");
			feedback.setCreateTime(new Date());
			feedback.setDel(Constant.DEL_NO);
			personService.insertFeedback(feedback);
			return new ResponseMsg("反馈成功", ErrorCode.OK, null);
		}catch(Exception e){
			e.printStackTrace();
			return new ResponseMsg("反馈失败", ErrorCode.SERVER_ERROR, null);
		}
	}
	
	public static void main(String[] args) {
		
	}
	
}
